home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 6
/
FM Towns Free Software Collection 6.iso
/
t_os
/
igo
/
src
/
kifuctrl.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-08
|
12KB
|
657 lines
#define DEBUG 0
/*
TOWNS囲碁棋譜記録プログラム
1992/02/25 久保田俊也
91/02/25 kifuctrl モジュールを本体より分離
kifuデ-タを操作する関数の集まり
*/
#include <stdio.h>
#include "igo.h"
#include "ban19.h"
#include "kiffile.h"
#define HEAD -1 /* ichiが-1の場合HEADとする */
#define SPACE20 " "
char *comment_read(int comment_no);
TE *cell_get();
TE_ARG cell_read();
static KIF_TITLE kif_title;
static TE *current_te;
static char ban[BANSIZE2];
static int numberdisp_flg = 1; /* 手順表示する 0以外 しない 0 */
static int repeat_flg = 0; /* リピ-トする 0以外 しない 0 */
static int change_flg = 0; /* 変化再生する 0以外 しない 0 */
static int comment_flg = 1; /* コメント表示する 0以外 しない 0 */
static TE *head;
int kifu_init()
{
int i;
cell_init();
head = cell_get();
comment_init();
kif_title.ver = 2; /* 93/3/1 変更 */
kif_title.handy = 0;
strcpy( kif_title.player_black , SPACE20);
strcpy( kif_title.player_white , SPACE20);
strcpy( kif_title.play_space , SPACE20);
kif_title.komi_id = -1;
kif_title.komi_number = -1;
kif_title.hanmoku_id = -1;
kif_title.vicdef_id = -1;
kif_title.vicdef_number = 0;
ban_init(19,ban);
head->iro = WHITE;
for(i=0;i<BANSIZE2;i++){
head->ban[i] = ban[i];
}
head->brother = head;
head->prev = head;
head->next = head;
head->ichi = HEAD; /* たぶん使わないだろうけど問題か headの判定使用*/
current_te = head;
return 0;
}
kifu_put(int ichi)
{
int i;
TE *add_te;
TE *temp;
#if DEBUG
printf("kifuctrl kifu_put!\n");
printf("ban[ichi] = %d ichi = %d\n", ban[ichi], ichi);
printf("current_te->iro = %d\n", current_te->iro);
#endif
if(ban[ichi]==BLACK || ban[ichi]==WHITE){
return 0;
}
if(current_te->next->iro == DELETE){
add_te = current_te->next;
}else{
add_te = cell_get();
if(add_te == NULL){
printf("return of cell_get() = null!\n");
return 1;
}
add_te->comment = 0;
/* 次の手に兄弟がない */
if(current_te->next == current_te->next->brother){
add_te->brother = add_te;
/* 次の手が枝の頭ではない */
}else if(current_te->next->ichi != HEAD){
add_te->brother = current_te->next->brother;
for(temp=current_te->next;
temp->brother != current_te->next;
temp=temp->brother){
;
}
current_te->next->brother = temp->brother;
temp->brother = add_te;
/* 次の手が枝の頭で かつ 一番下の弟である */
}else if(current_te->next->brother->ichi != HEAD ||
current_te->next->brother == head){
add_te->brother = add_te;
/* 次の手が枝の頭で かつ 下に弟がいる */
}else{
add_te->brother = current_te->next->brother;
for(temp=current_te->next;
temp->brother->ichi == HEAD && temp->brother != head;
temp=temp->brother){
;
}
current_te->next->brother = temp->brother;
temp->brother = add_te;
}
add_te->prev = current_te;
add_te->next = current_te->next;
current_te->next->prev = add_te;
current_te->next = add_te;
}
ban[ichi] = 1 - current_te->iro;
uchiage(ichi, ban);
add_te->ichi = ichi;
add_te->iro = 1 - current_te->iro;
for(i=0;i<BANSIZE2;i++){
add_te->ban[i] = ban[i];
}
current_te = add_te;
return 0;
}
kifu_cancel()
{
int i;
TE *save_te;
if(current_te->ichi == HEAD || current_te->iro == DELETE){
return -1;
}
if(current_te->brother != current_te || current_te->comment != 0){
current_te->iro = DELETE;
current_te = current_te->prev;
}else{
current_te->prev->next = current_te->next;
current_te->next->prev = current_te->prev;
save_te = current_te->prev;
cell_free(current_te);
current_te = save_te;
}
for(i=0;i<BANSIZE2;i++){
ban[i] = current_te->ban[i];
}
return 0;
}
int kifu_forward()
{
int i;
TE *wk_te;
TE *save_te;
save_te = current_te;
do{
current_te = current_te->next;
if( change_flg != 0){
if(current_te != current_te->brother){
current_te = current_te->brother;
}
}
}while(current_te->iro==DELETE);
if(current_te->ichi==HEAD){
if(repeat_flg == 0 && change_flg == 0){
current_te = save_te;
return REPEAT_CANNOT_BOTTOM_CELL;
}
if(current_te==head){
if(repeat_flg == 0){
current_te = save_te;
return REPEAT_CANNOT_BOTTOM_CELL;
}
for(i=0;i<BANSIZE2;i++){
ban[i] = current_te->ban[i];
}
return HEAD_CELL;
}else{
for(i=0;i<BANSIZE2;i++){
if(change_flg == 0){
ban[i] = current_te->ban[i];
}else{
current_te->ban[i] = ban[i];
}
}
return BOTTOM_CELL;
}
}else{
/* 打ち上げ処理を行うために前の画面に戻る */
for(wk_te=current_te->prev;wk_te->iro==DELETE;wk_te=wk_te->prev){
;
}
for(i=0;i<BANSIZE2;i++){
ban[i] = wk_te->ban[i];
}
ban[current_te->ichi] = current_te->iro;
uchiage(current_te->ichi, ban);
for(i=0;i<BANSIZE2;i++){
current_te->ban[i] = ban[i];
}
return NORMAL_CELL;
}
}
int kifu_back()
{
int i;
TE *wk_te;
if(repeat_flg == 0 && change_flg == 0){
if(current_te->ichi == HEAD){
for(i=0;i<BANSIZE2;i++){
ban[i] = current_te->ban[i] ;
}
return 0;
}
}else if(repeat_flg == 0 && change_flg != 0){
if(current_te == head){
for(i=0;i<BANSIZE2;i++){
ban[i] = current_te->ban[i] ;
}
return 0;
}
}
do{
if(change_flg != 0){
if(current_te->brother!=current_te){
for(wk_te=current_te;wk_te->brother!=current_te;wk_te=wk_te->brother){
;
}
current_te = wk_te;
}
}
current_te = current_te->prev;
}while(current_te->iro==DELETE);
for(i=0;i<BANSIZE2;i++){
ban[i] = current_te->ban[i] ;
}
return 0;
}
int kifu_first()
{
int i;
if(change_flg != 0){
current_te = head;
for(i=0;i<BANSIZE2;i++){
ban[i] = head->ban[i] ;
}
}else{
for(current_te=current_te->next;current_te->ichi!=HEAD;current_te=current_te->next){
;
}
for(i=0;i<BANSIZE2;i++){
ban[i] = current_te->ban[i];
}
}
return 0;
}
/* kifu_tmp_first()
{
int i;
current_te = tmp_head;
for(i=0;i<BANSIZE2;i++){
ban[i] = tmp_head->ban[i] ;
}
}*/
int kifu_read(char fname[])
{
int i;
KIF_TE kiffile_te;
TE_ARG kiffile_te2;
if(kiffile_read(fname) == -1){
return -1;
}
kiftitle_read(&kif_title);
current_te = head;
ban_init(19,ban);
if(kif_title.handy != 0){
handy_dispset(kif_title.handy, ban);
head->iro = BLACK;
}else{
head->iro = WHITE;
}
for(i=0;i<BANSIZE2;i++){
head->ban[i] = ban[i];
}
for(i=1;i <= kif_title.te_number;i++){
kifte_read2(&kiffile_te2);
if(cell_write(kiffile_te2)== -1){
printf("cell_write error = %d!\n", kif_title.te_number);
return -1;
}
}
if(cell_write_finish()== -1){
printf("cell_write error = %d!\n", kif_title.te_number);
return -1;
}
return 0;
}
kifu_write(char fname[])
{
TE_ARG kiffile_te;
kiftitle_write(kif_title);
kiffile_te = cell_read();
while(kiffile_te.no != -1){
kifte_write(kiffile_te);
kiffile_te = cell_read();
}
if(kiffile_write(fname) != 0){
return -1;
}
return 0;
}
kifu_handy(int handy)
{
int i;
if(handy_dispset(handy, ban) == 0){
for(i=0;i<BANSIZE2;i++){
head->ban[i] = ban[i];
}
kif_title.handy = handy;
head->iro = BLACK;
current_te = head;
}else{
return -1;
}
}
kifu_disp()
{
int i;
TE *wk_te;
static int ex_ban[BANSIZE2];
for(i=0;i<BANSIZE2;i++){
ex_ban[i] = 0;
}
if(numberdisp_flg != 0){
for(wk_te=current_te;wk_te->prev->ichi!=HEAD;wk_te=wk_te->prev){
;
}
i=1;
for(;wk_te!=current_te->next;wk_te=wk_te->next){
if(wk_te->iro != DELETE){
ex_ban[wk_te->ichi] = i;
i++;
}
}
}
disp_te(ban,ex_ban);
}
kifu_numberdisp()
{
numberdisp_flg = 1-numberdisp_flg;
}
kifu_print()
{
int i;
int handy;
int print_ban[BANSIZE2];
TE *wk_te;
struct {
int no;
int ichi;
int begin_no;
}print_bangai[BANSIZE2]; /* 配列の大きさはいい加減もっと大きくとるべきだろうがいい加減にきめてある */
for(i=0;i<BANSIZE2;i++){
print_ban[i] = 0;
print_bangai[i].no = 0;
print_bangai[i].ichi = 0;
print_bangai[i].begin_no = 0;
}
handy = kif_title.handy;
handy_prinset(handy, print_ban);
for(wk_te=head,i=0;wk_te->next!=head;wk_te=wk_te->next){
if(print_ban[wk_te->ichi]==0){
print_ban[wk_te->ichi] = i;
}else{
print_bangai[i].no = i;
print_bangai[i].ichi = wk_te->ichi;
print_bangai[i].begin_no = print_ban[wk_te->ichi];
i++;
}
}
/* 現在サポ-トしていない */
/* print(print_ban, print_bangai); */
}
kifu_chg_put()
{
int i;
TE *wk_te;
TE *tmp_head;
tmp_head = cell_get();
if(tmp_head == NULL){
return 1;
}
tmp_head->iro = current_te->iro;
tmp_head->ichi = HEAD;
for(i=0;i<BANSIZE2;i++){
tmp_head->ban[i] = ban[i];
}
for(wk_te = current_te->next;wk_te->brother !=wk_te;
wk_te = wk_te->brother->next){
;
}
wk_te->brother = tmp_head;
tmp_head->brother = wk_te;
tmp_head->prev = tmp_head;
tmp_head->next = tmp_head;
current_te = tmp_head;
return 0;
}
kifu_chg_cancel()
{
int i;
TE *wk_te;
if(current_te != current_te->next || current_te == head){
for(current_te=current_te->prev;current_te->ichi!=HEAD;current_te=current_te->prev){
;
}
do{
if(current_te->brother!=current_te){
for(wk_te=current_te;wk_te->brother!=current_te;wk_te=wk_te->brother){
;
}
current_te = wk_te;
}
current_te = current_te->prev;
}while(current_te->iro==DELETE);
for(i=0;i<BANSIZE2;i++){
ban[i] = current_te->ban[i];
}
return 0;
}
for(wk_te=current_te;wk_te->brother!=current_te;wk_te=wk_te->brother){
;
}
wk_te->brother = current_te->brother;
cell_free(current_te);
for(current_te=wk_te->prev;current_te->iro==DELETE;current_te=current_te->prev){
;
}
for(i=0;i<BANSIZE2;i++){
ban[i] = current_te->ban[i];
}
return 0;
}
int kifu_rebirth( int repeat_flag, int change_flag, int comment_flag )
{
repeat_flg = repeat_flag;
change_flg = change_flag;
comment_flg = comment_flag;
return 0;
}
int kifu_blacknameset(char *blackname)
{
if(strlen(blackname) >= 21){
return -1;
}
strcpy( kif_title.player_black, blackname);
return 0;
}
int kifu_blacknameread(char *blackname)
{
strcpy( blackname, kif_title.player_black);
return 0;
}
int kifu_whitenameset(char *whitename)
{
if(strlen(whitename) >= 21){
return -1;
}
strcpy( kif_title.player_white, whitename);
return 0;
}
int kifu_whitenameread(char *whitename)
{
strcpy( whitename, kif_title.player_white);
return 0;
}
int kifu_playspaceset(char *play_space)
{
if(strlen(play_space) >= 21){
return -1;
}
strcpy( kif_title.play_space, play_space);
return 0;
}
int kifu_playspaceread(char *play_space)
{
strcpy( play_space, kif_title.play_space);
return 0;
}
int kifu_komiset(int komi_id, int komi_number, int hanmoku_id)
{
kif_title.komi_id = komi_id;
kif_title.komi_number = komi_number;
kif_title.hanmoku_id = hanmoku_id;
return 0;
}
int kifu_komiread(int *komi_id, int *komi_number, int *hanmoku_id)
{
*komi_id = kif_title.komi_id;
*komi_number = kif_title.komi_number;
*hanmoku_id = kif_title.hanmoku_id;
return 0;
}
int kifu_issueset(int vicdef_id, int vicdef_number)
{
kif_title.vicdef_id = vicdef_id;
kif_title.vicdef_number = vicdef_number;
return 0;
}
int kifu_issueread(int *vicdef_id, int *vicdef_number)
{
*vicdef_id = kif_title.vicdef_id;
*vicdef_number = kif_title.vicdef_number;
return 0;
}
int kifu_playstart_time_set(YMDHM play_start)
{
kif_title.play_start = play_start;
return 0;
}
YMDHM *kifu_playstart_time_read()
{
return &(kif_title.play_start);
}
int kifu_playend_time_set(YMDHM play_end)
{
kif_title.play_end = play_end;
return 0;
}
YMDHM *kifu_playend_time_read()
{
return &(kif_title.play_end);
}
int kifu_commentset(char *text)
{
int comment_no;
comment_no = comment_set(text);
current_te->comment = (short int)comment_no;
return 0;
}
char *kifu_commentread()
{
return comment_read((int)current_te->comment);
}